package store.lunangangster.engine.impl.entity.mgr;

import java.util.List;
import store.lunangangster.engine.impl.entity.ExecutionEntity;
import store.lunangangster.engine.impl.query.ExecutionQuery;
import store.lunangangster.engine.repository.ProcessDefinition;

public interface ExecutionEntityManager extends EntityManager<ExecutionEntity> {

  ExecutionEntity createProcessInstanceExecution(ProcessDefinition processDefinition, String processInstanceName);

  ExecutionEntity createChildExecution(ExecutionEntity parentExecution);

  ExecutionEntity createBrotherExecution(ExecutionEntity brotherExecution);

  void deleteProcessInstanceExecution(String processInstanceId);

  void deleteChildExecution(ExecutionEntity parentExecution);

  /**
   * 该方法会删除指定的Execution以及与之相关的IdentityLink、Task
   * @param execution 待删除Execution对象
   */
  void deleteExecution(ExecutionEntity execution);

  /**
   * 该方法会递归获取父Execution下所有的子Execution，结果会是一棵Execution树。
   * <p>结果树是前序遍历序列，在该树中，所有的父节点一定位于子节点之前。从后往前进行遍历结果树，
   * 一定会保证子节点的优先遍历
   *
   * @param parentExecution 根节点
   * @return  所有孩子的一棵前序遍历树
   */
  List<ExecutionEntity> collectionChildExecutionRecursive(ExecutionEntity parentExecution);

  List<ExecutionEntity> selectExecutionList(List<String> ids);

  List<ExecutionEntity> selectExecutionByCondition(ExecutionQuery query);

  List<ExecutionEntity> selectChildExecutionByProcessInstanceId(String processInstanceId);

  List<ExecutionEntity> selectExecutionByProcessDefinitionId(String processDefinitionId);

  List<ExecutionEntity> selectChildExecutionByParentId(String parentId);

}
